Skip to content

added: support box constraint in LinMPC and NonLinMPC#379

Open
franckgaga wants to merge 10 commits into
mainfrom
box_constraints
Open

added: support box constraint in LinMPC and NonLinMPC#379
franckgaga wants to merge 10 commits into
mainfrom
box_constraints

Conversation

@franckgaga

@franckgaga franckgaga commented Jun 18, 2026

Copy link
Copy Markdown
Member

Following discussion at #378, it is a good idea in terms of performances to treat constraints on the decision variable as box constraints, instead of linear inequality constraints, at least for NLP and interior point methods.

In this PR, these constraints:

  • limit on slack variable $\epsilon > 0$
  • limits on the input increments $\mathbf{\Delta u}$,
  • limits on the terminal state $\mathbf{\hat{x}}(k+H_p)$ for non-SingleShooting

are treated as box constraints. It applies to both LinMPC and NonLinMPC. Note that if there is a nonzero value in the associated softness parameters $\mathbf{c_{(\bullet)}}$ it is no longer a box constraint and the associated bound is treated as a linear inequality constraint, like before.

The default QP solver for LinMPC is OSQP.jl, and it does not support box constraint natively. It is still possible to define box constraints with the bridge mechanism of JuMP.jl. The new default optim argument for LinMPC is optim=JuMP.Model(OSQP.MathOptInterfaceOSQP.Optimizer, add_bridges=true). It should not affect the performances since JuMP will automatically convert them as linear equality constraints, as it was the case before this PR. It's possible that the performances with DAQP.jl will be improved however, since it supports box constraints natively.

Warning

Constructing LinMPC with optim=JuMP.Model(OSQP.MathOptInterfaceOSQP.Optimizer, add_bridges=false) will now throw an error. Please use add_bridges=true (it should not affect performances).

Let's see the benchmarks.

@codecov-commenter

codecov-commenter commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.60%. Comparing base (ed09542) to head (2f2cd11).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #379      +/-   ##
==========================================
+ Coverage   98.58%   98.60%   +0.01%     
==========================================
  Files          27       27              
  Lines        5512     5591      +79     
==========================================
+ Hits         5434     5513      +79     
  Misses         78       78              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

Benchmark Results (Julia v1)

Time benchmarks
main 4751d5e... main / 4751d5e...
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/DAQP/SingleShooting 5.61 ± 0.48 ms 5.78 ± 0.49 ms 0.971 ± 0.12
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/MultipleShooting 11.8 ± 0.72 ms 11.7 ± 0.71 ms 1 ± 0.086
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/SingleShooting 2.27 ± 0.14 ms 1.94 ± 0.11 ms 1.17 ± 0.094
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/DAQP/SingleShooting 5.57 ± 0.46 ms 5.68 ± 0.55 ms 0.981 ± 0.13
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/MultipleShooting 8.1 ± 0.47 ms 8.07 ± 0.47 ms 1 ± 0.083
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/SingleShooting 2.16 ± 0.12 ms 2.11 ± 0.097 ms 1.02 ± 0.075
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/DAQP/SingleShooting 10.1 ± 1.4 ms 9.77 ± 1.4 ms 1.04 ± 0.21
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/MultipleShooting 0.111 ± 0.023 s 0.11 ± 0.021 s 1.01 ± 0.28
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/SingleShooting 15 ± 1.9 ms 14.9 ± 1.8 ms 1.01 ± 0.18
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/MultipleShooting 0.708 ± 0.0042 s 0.876 ± 0.0071 s 0.809 ± 0.0081
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/MultipleShooting (Hessian) 0.633 ± 0.0067 s 1.19 ± 0.0092 s 0.53 ± 0.0069
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/SingleShooting 1.86 ± 0.0067 s 1.38 ± 0.0096 s 1.35 ± 0.011
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/TrapezoidalCollocation 0.483 ± 0.005 s 0.915 ± 0.0062 s 0.528 ± 0.0065
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/TrapezoidalCollocation (Hessian) 0.483 ± 0.0057 s 0.918 ± 0.0062 s 0.526 ± 0.0071
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/MultipleShooting 0.359 ± 0.0025 s 0.383 ± 0.0031 s 0.936 ± 0.01
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/MultipleShooting (Hessian) 0.42 ± 0.0053 s 0.428 ± 0.005 s 0.982 ± 0.017
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/OrthogonalCollocation 0.533 ± 0.0032 s 0.549 ± 0.0033 s 0.971 ± 0.0082
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/OrthogonalCollocation (Hessian) 0.545 ± 0.0046 s 0.57 ± 0.0057 s 0.955 ± 0.013
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/SingleShooting 0.532 ± 0.003 s 0.536 ± 0.0026 s 0.994 ± 0.0074
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/SingleShooting (Hessian) 0.186 ± 0.0018 s 0.202 ± 0.0015 s 0.925 ± 0.011
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/TrapezoidalCollocation 0.333 ± 0.0031 s 0.358 ± 0.0025 s 0.93 ± 0.011
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/TrapezoidalCollocation (Hessian) 0.324 ± 0.0023 s 0.342 ± 0.0037 s 0.949 ± 0.012
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/MadNLP/SingleShooting (Hessian) 0.0838 ± 0.0016 s 0.0848 ± 0.0013 s 0.988 ± 0.024
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Uno/MultipleShooting (Hessian) 0.195 ± 0.01 s 0.203 ± 0.011 s 0.962 ± 0.074
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/MultipleShooting 0.35 ± 0.003 s 0.35 ± 0.0026 s 1 ± 0.011
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/MultipleShooting (Hessian) 0.362 ± 0.0053 s 0.365 ± 0.003 s 0.99 ± 0.017
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/MultipleShooting (threaded) 0.368 ± 0.0049 s 0.371 ± 0.0029 s 0.991 ± 0.015
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/OrthogonalCollocation 0.596 ± 0.0038 s 0.601 ± 0.0028 s 0.991 ± 0.0079
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/OrthogonalCollocation (Hessian) 1.74 ± 0.032 s 1.74 ± 0.028 s 0.998 ± 0.024
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/SingleShooting 0.532 ± 0.0028 s 0.532 ± 0.0044 s 1 ± 0.0098
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/SingleShooting (Hessian) 0.179 ± 0.0013 s 0.184 ± 0.0017 s 0.975 ± 0.011
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/TrapezoidalCollocation 0.332 ± 0.0028 s 0.341 ± 0.0018 s 0.973 ± 0.0096
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/TrapezoidalCollocation (Hessian) 0.279 ± 0.0019 s 0.281 ± 0.0025 s 0.991 ± 0.011
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/TrapezoidalCollocation (threaded) 0.355 ± 0.0031 s 0.363 ± 0.0049 s 0.978 ± 0.016
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/MadNLP/MultipleShooting (Hessian) 0.246 ± 0.0026 s 0.243 ± 0.0019 s 1.01 ± 0.014
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/MadNLP/SingleShooting (Hessian) 0.0783 ± 0.00092 s 0.0788 ± 0.0009 s 0.994 ± 0.016
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Uno/MultipleShooting (Hessian) 0.178 ± 0.0026 s 0.178 ± 0.0022 s 0.999 ± 0.019
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Uno/OrthogonalCollocation (Hessian) 0.828 ± 0.0087 s 0.836 ± 0.0097 s 0.99 ± 0.016
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Current form 0.0704 ± 0.0028 s 0.0739 ± 0.0026 s 0.952 ± 0.051
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Prediction form 0.052 ± 0.0025 s 0.0556 ± 0.0037 s 0.935 ± 0.076
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Current form 0.0639 ± 0.0055 s 0.0679 ± 0.0048 s 0.941 ± 0.1
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Prediction form 0.0458 ± 0.005 s 0.0468 ± 0.0051 s 0.978 ± 0.15
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Current form 0.0932 ± 0.0014 s 0.0925 ± 0.00088 s 1.01 ± 0.018
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Current form (Hessian) 0.0937 ± 0.0013 s 0.0908 ± 0.001 s 1.03 ± 0.018
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Prediction form 0.0697 ± 0.00058 s 0.0692 ± 0.00097 s 1.01 ± 0.016
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Prediction form (Hessian) 0.0918 ± 0.00064 s 0.0891 ± 0.00068 s 1.03 ± 0.011
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Current form (Hessian) 0.0503 ± 0.0011 s 0.0493 ± 0.00081 s 1.02 ± 0.028
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Prediction form (Hessian) 0.047 ± 0.00052 s 0.0455 ± 0.00068 s 1.03 ± 0.019
UNIT TESTS/PredictiveController/ExplicitMPC/moveinput! 4.02 ± 0.049 μs 4.17 ± 0.021 μs 0.964 ± 0.013
UNIT TESTS/PredictiveController/LinMPC/getinfo! 0.111 ± 0.0031 ms 0.111 ± 0.0035 ms 0.996 ± 0.042
UNIT TESTS/PredictiveController/LinMPC/moveinput!/MultipleShooting 0.109 ± 0.0015 ms 0.135 ± 0.0094 ms 0.809 ± 0.057
UNIT TESTS/PredictiveController/LinMPC/moveinput!/SingleShooting 16.2 ± 0.42 μs 17.3 ± 0.37 μs 0.937 ± 0.032
UNIT TESTS/PredictiveController/NonLinMPC/getinfo!/LinModel 0.195 ± 0.012 ms 0.168 ± 0.017 ms 1.16 ± 0.14
UNIT TESTS/PredictiveController/NonLinMPC/getinfo!/NonLinModel 0.225 ± 0.019 ms 0.287 ± 0.055 ms 0.784 ± 0.16
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/MultipleShooting 1.49 ± 0.24 ms 1.07 ± 0.19 ms 1.4 ± 0.34
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/SingleShooting 0.992 ± 0.021 ms 0.469 ± 0.028 ms 2.11 ± 0.13
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/MultipleShooting 2.43 ± 0.71 ms 10.5 ± 0.45 ms 0.231 ± 0.068
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/MultipleShootingHessian 2.27 ± 0.092 ms 10.5 ± 0.38 ms 0.217 ± 0.012
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/OrthogonalCollocation 2.2 ± 0.28 ms 11.4 ± 1.5 ms 0.193 ± 0.035
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/OrthogonalCollocationHessian 3.04 ± 0.16 ms 10.6 ± 0.5 ms 0.288 ± 0.021
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/SingleShooting 1.3 ± 0.044 ms 7.82 ± 0.4 ms 0.166 ± 0.01
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/SingleShootingHessian 1.29 ± 0.038 ms 7.77 ± 0.54 ms 0.166 ± 0.013
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/TrapezoidalCollocation 1.68 ± 0.19 ms 7.42 ± 0.36 ms 0.226 ± 0.028
UNIT TESTS/SimModel/LinModel/evaloutput 0.13 ± 0.001 μs 0.14 ± 0.01 μs 0.929 ± 0.067
UNIT TESTS/SimModel/LinModel/updatestate! 0.18 ± 0.001 μs 0.19 ± 0.001 μs 0.947 ± 0.0073
UNIT TESTS/SimModel/NonLinModel/evaloutput 0.391 ± 0.01 μs 0.39 ± 0.01 μs 1 ± 0.036
UNIT TESTS/SimModel/NonLinModel/linearize! 1.91 ± 0.02 μs 1.95 ± 0.03 μs 0.98 ± 0.018
UNIT TESTS/SimModel/NonLinModel/updatestate! 0.451 ± 0 μs 0.441 ± 0.01 μs 1.02 ± 0.023
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/LinModel 0.511 ± 0.01 μs 0.521 ± 0.01 μs 0.981 ± 0.027
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/NonLinModel 1.78 ± 0.019 μs 1.75 ± 0.019 μs 1.02 ± 0.015
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/preparestate!/LinModel 0.24 ± 0.001 μs 0.251 ± 0.01 μs 0.956 ± 0.038
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/preparestate!/NonLinModel 1.41 ± 0.01 μs 1.39 ± 0.001 μs 1.01 ± 0.0072
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/updatestate!/LinModel 3.98 ± 0.04 μs 4.06 ± 0.05 μs 0.981 ± 0.016
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/updatestate!/NonLinModel 8.61 ± 0.089 μs 8.43 ± 0.071 μs 1.02 ± 0.014
UNIT TESTS/StateEstimator/InternalModel/evaloutput/LinModel 0.251 ± 0.001 μs 0.241 ± 0.01 μs 1.04 ± 0.043
UNIT TESTS/StateEstimator/InternalModel/evaloutput/NonLinModel 0.571 ± 0.01 μs 0.571 ± 0.01 μs 1 ± 0.025
UNIT TESTS/StateEstimator/InternalModel/preparestate!/LinModel 0.3 ± 0.01 μs 0.311 ± 0.001 μs 0.965 ± 0.032
UNIT TESTS/StateEstimator/InternalModel/preparestate!/NonLinModel 0.721 ± 0.001 μs 0.722 ± 0.01 μs 0.999 ± 0.014
UNIT TESTS/StateEstimator/InternalModel/updatestate!/LinModel 0.45 ± 0.01 μs 0.45 ± 0.01 μs 1 ± 0.031
UNIT TESTS/StateEstimator/InternalModel/updatestate!/NonLinModel 1.23 ± 0.011 μs 1.24 ± 0.019 μs 0.992 ± 0.018
UNIT TESTS/StateEstimator/KalmanFilter/evaloutput 0.251 ± 0.01 μs 0.251 ± 0.01 μs 1 ± 0.056
UNIT TESTS/StateEstimator/KalmanFilter/preparestate! 0.13 ± 0.01 μs 0.13 ± 0 μs 1 ± 0.077
UNIT TESTS/StateEstimator/KalmanFilter/updatestate! 2.46 ± 0.039 μs 2.46 ± 0.031 μs 1 ± 0.02
UNIT TESTS/StateEstimator/Luenberger/evaloutput 0.24 ± 0.01 μs 0.24 ± 0.01 μs 1 ± 0.059
UNIT TESTS/StateEstimator/Luenberger/preparestate! 0.241 ± 0.01 μs 0.24 ± 0.01 μs 1 ± 0.059
UNIT TESTS/StateEstimator/Luenberger/updatestate! 0.33 ± 0.01 μs 0.331 ± 0.01 μs 0.997 ± 0.043
UNIT TESTS/StateEstimator/MovingHorizonEstimator/getinfo!/LinModel 0.258 ± 0.028 ms 0.27 ± 0.016 ms 0.958 ± 0.12
UNIT TESTS/StateEstimator/MovingHorizonEstimator/getinfo!/NonLinModel 0.353 ± 0.022 ms 0.352 ± 0.022 ms 1 ± 0.087
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Constant arr. cov. 30.2 ± 2.3 ms 29.8 ± 1.8 ms 1.01 ± 0.098
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Current form 30.6 ± 2.6 ms 30.2 ± 1.5 ms 1.01 ± 0.1
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Prediction form 0.501 ± 0.01 μs 0.511 ± 0.01 μs 0.98 ± 0.027
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Current form 0.306 ± 0.022 ms 0.312 ± 0.022 ms 0.979 ± 0.098
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Prediction form 1.43 ± 0.01 μs 1.4 ± 0.01 μs 1.02 ± 0.01
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Constant arr. cov. 11.4 ± 1.3 μs 12.2 ± 1.5 μs 0.934 ± 0.16
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Current form 30.4 ± 5.3 μs 0.0327 ± 0.0034 ms 0.93 ± 0.19
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Prediction form 28.3 ± 2.3 ms 27.8 ± 2.2 ms 1.02 ± 0.11
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Current form 16.9 ± 0.69 μs 17 ± 0.49 μs 0.996 ± 0.05
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Prediction form 0.325 ± 0.022 ms 0.32 ± 0.023 ms 1.02 ± 0.1
UNIT TESTS/StateEstimator/SteadyKalmanFilter/evaloutput 0.251 ± 0.01 μs 0.26 ± 0.011 μs 0.965 ± 0.056
UNIT TESTS/StateEstimator/SteadyKalmanFilter/preparestate! 0.261 ± 0.001 μs 0.27 ± 0.01 μs 0.967 ± 0.036
UNIT TESTS/StateEstimator/SteadyKalmanFilter/updatestate! 0.371 ± 0.011 μs 0.341 ± 0.011 μs 1.09 ± 0.048
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/LinModel 0.311 ± 0.001 μs 0.311 ± 0.01 μs 1 ± 0.032
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/NonLinModel 0.922 ± 0.01 μs 0.932 ± 0.011 μs 0.989 ± 0.016
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/LinModel 3.65 ± 0.07 μs 3.6 ± 0.031 μs 1.01 ± 0.021
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/NonLinModel 4.9 ± 0.07 μs 4.81 ± 0.03 μs 1.02 ± 0.016
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/LinModel 3.58 ± 0.07 μs 3.51 ± 0.031 μs 1.02 ± 0.022
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/NonLinModel 6.15 ± 0.051 μs 6.21 ± 0.06 μs 0.99 ± 0.013
time_to_load 6.05 ± 0.12 s 6.15 ± 0.04 s 0.984 ± 0.021
Memory benchmarks
main 4751d5e... main / 4751d5e...
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/DAQP/SingleShooting 0.0469 M allocs: 1.85 MB 0.0489 M allocs: 1.86 MB 0.993
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/MultipleShooting 0.126 M allocs: 3.16 MB 0.126 M allocs: 3.16 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/With feedforward/OSQP/SingleShooting 12.9 k allocs: 0.361 MB 12.6 k allocs: 0.356 MB 1.01
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/DAQP/SingleShooting 0.0468 M allocs: 1.84 MB 0.0487 M allocs: 1.85 MB 0.993
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/MultipleShooting 0.0882 M allocs: 2.23 MB 0.0879 M allocs: 2.23 MB 1
CASE STUDIES/PredictiveController/CSTR/LinMPC/Without feedforward/OSQP/SingleShooting 12.8 k allocs: 0.355 MB 12.5 k allocs: 0.35 MB 1.01
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/DAQP/SingleShooting 0.119 M allocs: 6.37 MB 0.119 M allocs: 6.37 MB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/MultipleShooting 4.76 M allocs: 0.257 GB 4.75 M allocs: 0.257 GB 1
CASE STUDIES/PredictiveController/Pendulum/LinMPC/Successive linearization/OSQP/SingleShooting 0.149 M allocs: 8.5 MB 0.148 M allocs: 8.22 MB 1.03
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/MultipleShooting 0.435 M allocs: 30.3 MB 0.626 M allocs: 0.0433 GB 0.684
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/MultipleShooting (Hessian) 1.04 M allocs: 0.114 GB 1.99 M allocs: 0.22 GB 0.518
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/SingleShooting 0.359 M allocs: 0.0504 GB 0.231 M allocs: 0.0324 GB 1.56
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/TrapezoidalCollocation 1.02 M allocs: 0.0978 GB 2.01 M allocs: 0.196 GB 0.499
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Custom constraints/Ipopt/TrapezoidalCollocation (Hessian) 1.02 M allocs: 0.0978 GB 2.01 M allocs: 0.196 GB 0.499
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/MultipleShooting 0.316 M allocs: 22 MB 0.316 M allocs: 22 MB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/MultipleShooting (Hessian) 0.741 M allocs: 0.0843 GB 0.741 M allocs: 0.0843 GB 0.999
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/OrthogonalCollocation 1.33 M allocs: 0.119 GB 1.33 M allocs: 0.119 GB 0.999
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/OrthogonalCollocation (Hessian) 1.33 M allocs: 0.119 GB 1.33 M allocs: 0.119 GB 0.999
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/SingleShooting 0.0965 M allocs: 17.6 MB 0.0965 M allocs: 17.6 MB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/SingleShooting (Hessian) 0.0812 M allocs: 16.8 MB 0.0812 M allocs: 16.9 MB 0.993
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/TrapezoidalCollocation 0.314 M allocs: 21.8 MB 0.314 M allocs: 21.9 MB 0.996
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Ipopt/TrapezoidalCollocation (Hessian) 0.757 M allocs: 0.0765 GB 0.757 M allocs: 0.0765 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/MadNLP/SingleShooting (Hessian) 0.0926 M allocs: 19.8 MB 0.0926 M allocs: 20 MB 0.994
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Economic/Uno/MultipleShooting (Hessian) 0.311 M allocs: 0.0327 GB 0.311 M allocs: 0.0327 GB 0.999
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/MultipleShooting 0.277 M allocs: 19 MB 0.277 M allocs: 19 MB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/MultipleShooting (Hessian) 0.709 M allocs: 0.0738 GB 0.709 M allocs: 0.0739 GB 0.999
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/MultipleShooting (threaded) 0.296 M allocs: 28 MB 0.296 M allocs: 28 MB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/OrthogonalCollocation 1.43 M allocs: 0.128 GB 1.43 M allocs: 0.128 GB 0.999
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/OrthogonalCollocation (Hessian) 5.12 M allocs: 0.601 GB 5.12 M allocs: 0.601 GB 0.999
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/SingleShooting 0.0754 M allocs: 13.3 MB 0.0754 M allocs: 13.3 MB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/SingleShooting (Hessian) 0.0808 M allocs: 16.8 MB 0.0808 M allocs: 16.9 MB 0.993
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/TrapezoidalCollocation 0.276 M allocs: 19 MB 0.276 M allocs: 19 MB 0.996
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/TrapezoidalCollocation (Hessian) 0.72 M allocs: 0.0656 GB 0.72 M allocs: 0.0656 GB 1
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Ipopt/TrapezoidalCollocation (threaded) 0.295 M allocs: 28 MB 0.295 M allocs: 28.1 MB 0.997
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/MadNLP/MultipleShooting (Hessian) 0.587 M allocs: 0.0728 GB 0.587 M allocs: 0.0728 GB 0.999
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/MadNLP/SingleShooting (Hessian) 0.0927 M allocs: 19.9 MB 0.0927 M allocs: 20 MB 0.994
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Uno/MultipleShooting (Hessian) 0.307 M allocs: 30.3 MB 0.307 M allocs: 30.3 MB 0.999
CASE STUDIES/PredictiveController/Pendulum/NonLinMPC/Noneconomic/Uno/OrthogonalCollocation (Hessian) 2.13 M allocs: 0.243 GB 2.13 M allocs: 0.243 GB 0.999
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Current form 1.25 M allocs: 0.213 GB 1.25 M allocs: 0.215 GB 0.988
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/DAQP/Prediction form 1.16 M allocs: 0.136 GB 1.16 M allocs: 0.136 GB 0.999
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Current form 1.13 M allocs: 0.21 GB 1.13 M allocs: 0.21 GB 1
CASE STUDIES/StateEstimator/CSTR/MovingHorizonEstimator/OSQP/Prediction form 1.07 M allocs: 0.134 GB 1.07 M allocs: 0.134 GB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Current form 0.0691 M allocs: 12.1 MB 0.0691 M allocs: 12.1 MB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Current form (Hessian) 0.0682 M allocs: 12 MB 0.0682 M allocs: 12 MB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Prediction form 0.0521 M allocs: 8.54 MB 0.0521 M allocs: 8.54 MB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/Ipopt/Prediction form (Hessian) 0.0684 M allocs: 12.1 MB 0.0684 M allocs: 12.1 MB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Current form (Hessian) 0.0902 M allocs: 16 MB 0.0902 M allocs: 16 MB 1
CASE STUDIES/StateEstimator/Pendulum/MovingHorizonEstimator/MadNLP/Prediction form (Hessian) 0.0851 M allocs: 14.7 MB 0.0851 M allocs: 14.7 MB 1
UNIT TESTS/PredictiveController/ExplicitMPC/moveinput! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/PredictiveController/LinMPC/getinfo! 0.327 k allocs: 15.8 kB 0.326 k allocs: 15.6 kB 1.01
UNIT TESTS/PredictiveController/LinMPC/moveinput!/MultipleShooting 0.994 k allocs: 25.5 kB 1.62 k allocs: 0.0403 MB 0.618
UNIT TESTS/PredictiveController/LinMPC/moveinput!/SingleShooting 0.088 k allocs: 2.23 kB 0.114 k allocs: 2.98 kB 0.749
UNIT TESTS/PredictiveController/NonLinMPC/getinfo!/LinModel 0.482 k allocs: 0.0604 MB 0.408 k allocs: 0.0579 MB 1.04
UNIT TESTS/PredictiveController/NonLinMPC/getinfo!/NonLinModel 0.614 k allocs: 0.0785 MB 0.571 k allocs: 0.077 MB 1.02
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/MultipleShooting 1.89 k allocs: 0.11 MB 1.79 k allocs: 0.105 MB 1.05
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/LinModel/SingleShooting 0.431 k allocs: 18.1 kB 0.254 k allocs: 10.1 kB 1.79
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/MultipleShooting 2.29 k allocs: 0.143 MB 4.76 k allocs: 0.368 MB 0.388
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/MultipleShootingHessian 2.88 k allocs: 0.198 MB 5.34 k allocs: 0.423 MB 0.468
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/OrthogonalCollocation 3.78 k allocs: 0.22 MB 9.58 k allocs: 0.609 MB 0.361
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/OrthogonalCollocationHessian 7.62 k allocs: 0.681 MB 0.0459 M allocs: 4.44 MB 0.154
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/SingleShooting 0.333 k allocs: 0.0473 MB 0.957 k allocs: 0.233 MB 0.203
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/SingleShootingHessian 0.333 k allocs: 0.0473 MB 0.957 k allocs: 0.233 MB 0.203
UNIT TESTS/PredictiveController/NonLinMPC/moveinput!/NonLinModel/TrapezoidalCollocation 1.45 k allocs: 0.0898 MB 3.42 k allocs: 0.241 MB 0.373
UNIT TESTS/SimModel/LinModel/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/SimModel/LinModel/updatestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/SimModel/NonLinModel/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/SimModel/NonLinModel/linearize! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/SimModel/NonLinModel/updatestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/evaloutput/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/preparestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/preparestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/updatestate!/LinModel 4 allocs: 0.0938 kB 4 allocs: 0.0938 kB 1
UNIT TESTS/StateEstimator/ExtendedKalmanFilter/updatestate!/NonLinModel 4 allocs: 0.0938 kB 4 allocs: 0.0938 kB 1
UNIT TESTS/StateEstimator/InternalModel/evaloutput/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/evaloutput/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/preparestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/preparestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/updatestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/InternalModel/updatestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/KalmanFilter/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/KalmanFilter/preparestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/KalmanFilter/updatestate! 4 allocs: 0.0938 kB 4 allocs: 0.0938 kB 1
UNIT TESTS/StateEstimator/Luenberger/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/Luenberger/preparestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/Luenberger/updatestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/getinfo!/LinModel 1.01 k allocs: 0.0405 MB 1.01 k allocs: 0.0405 MB 1
UNIT TESTS/StateEstimator/MovingHorizonEstimator/getinfo!/NonLinModel 1.27 k allocs: 0.167 MB 1.27 k allocs: 0.167 MB 1
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Constant arr. cov. 0.158 M allocs: 0.114 GB 0.158 M allocs: 0.116 GB 0.984
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Current form 0.158 M allocs: 0.115 GB 0.158 M allocs: 0.115 GB 0.997
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/LinModel/Prediction form 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Current form 0.977 k allocs: 25.3 kB 0.977 k allocs: 25.3 kB 1
UNIT TESTS/StateEstimator/MovingHorizonEstimator/preparestate!/NonLinModel/Prediction form 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Constant arr. cov. 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Current form 2 allocs: 0.0469 kB 2 allocs: 0.0469 kB 1
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/LinModel/Prediction form 7.08 k allocs: 0.451 MB 7.08 k allocs: 0.451 MB 1
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Current form 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/MovingHorizonEstimator/updatestate!/NonLinModel/Prediction form 0.977 k allocs: 25.3 kB 0.977 k allocs: 25.3 kB 1
UNIT TESTS/StateEstimator/SteadyKalmanFilter/evaloutput 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/SteadyKalmanFilter/preparestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/SteadyKalmanFilter/updatestate! 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/evaloutput/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/preparestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/LinModel 0 allocs: 0 B 0 allocs: 0 B
UNIT TESTS/StateEstimator/UnscentedKalmanFilter/updatestate!/NonLinModel 0 allocs: 0 B 0 allocs: 0 B
time_to_load 0.149 k allocs: 11.2 kB 0.149 k allocs: 11.2 kB 1

@franckgaga

franckgaga commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Wow these terrible results haha ⁉️⁉️⁉️

I did something wrong for sure 😆

@franckgaga

franckgaga commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Okay I ran some of the benchmark locally and many case studies did not converge anymore, that's why. There's presumably a nasty bug hidden somewhere.

I just modify them on `setconstraint!` calls
@franckgaga

franckgaga commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

Okay I have this MRE that converge to the best solution (at least a very good solution) on main, but a very bad solution in this branch:

using ModelPredictiveControl, ControlSystemsBase, JuMP, Ipopt, BenchmarkTools

function f!(ẋ, x, u, _ , p)
    g, L, K, m = p
    θ, ω = x[1], x[2]
    τ = u[1]
    ẋ[1] = ω
    ẋ[2] = -g/L*sin(θ) - K/m*ω + τ/m/L^2
end
h!(y, x, _ , _ ) = (y[1] = 180/π*x[1])
p = [9.8, 0.4, 1.2, 0.3]
nu = 1; nx = 2; ny = 1; Ts = 0.1
pendulum_model = NonLinModel(f!, h!, Ts, nu, nx, ny; p)
pendulum_p = p

h2!(y, x, _ , _ ) = (y[1] = 180/π*x[1]; y[2]=x[2])
nu, nx, ny = 1, 2, 2
pendulum_model2 = NonLinModel(f!, h2!, Ts, nu, nx, ny; p)
pendulum_p2 = p

Hp, Hc, Mwt, Nwt, Cwt = 20, 2, [0.5], [2.5], Inf
umin, umax = [-1.5], [+1.5]

model2, p = pendulum_model2, pendulum_p2
plant2 = deepcopy(model2)
plant2.p[3] = 1.25*p[3]  # plant-model mismatch
σQ = [0.1, 1.0]; σR=[5.0]; nint_u=[1]; σQint_u=[0.1]
estim2 = UnscentedKalmanFilter(model2; σQ, σR, nint_u, σQint_u, i_ym=[1])
function JE(UE, ŶE, _ , p, _)
    Ts = p
    τ, ω = @views UE[1:end-1], ŶE[2:2:end-1]
    return Ts*dot(τ, ω)
end
p = Ts; Mwt2 = [Mwt; 0.0]; Ewt = 3.5e3
x_0 = [0, 0]; x̂_0 = [0, 0, 0]; ry = [180; 0]

function gc!(LHS, Ue, Ŷe, _, p, ϵ)
    Pmax = p
    i_τ, i_ω = 1, 2
    for i in eachindex(LHS)
        τ, ω = Ue[i_τ], Ŷe[i_ω]
        P = τ*ω
        LHS[i] = P - Pmax - ϵ
        i_τ += 1
        i_ω += 2
    end
    return nothing
end
Cwt, Pmax, nc = 1e5, 3, Hp+1
x_0 = [0, 0]; x̂_0 = [0, 0, 0]; ry = [180; 0]

N = 35

optim = JuMP.Model(optimizer_with_attributes(Ipopt.Optimizer,"sb"=>"yes"), add_bridges=false)
transcription = MultipleShooting()
nmpc2_ipopt_ms = NonLinMPC(estim2; 
    Hp, Hc, Nwt=Nwt, Mwt=[0.5, 0], Cwt, gc!, nc, p=Pmax, optim, transcription
)
nmpc2_ipopt_ms = setconstraint!(nmpc2_ipopt_ms; umin, umax)
JuMP.unset_time_limit_sec(nmpc2_ipopt_ms.optim)

samples, evals, seconds = 100, 1, 15*60
# @btime(
#     sim!($nmpc2_ipopt_ms, $N, $ry; plant=$plant2, x_0=$x_0, x̂_0=$x̂_0, progress=false),
#     samples=samples, evals=evals, seconds=seconds, setup=GC.gc()
# )

unset_silent(nmpc2_ipopt_ms.optim)
initstate!(nmpc2_ipopt_ms, [0], [0])
setstate!(nmpc2_ipopt_ms, x̂_0)

preparestate!(nmpc2_ipopt_ms, [0])
u = moveinput!(nmpc2_ipopt_ms, ry)

We can see that the objective increases throughtout the iterrations:

This is Ipopt version 3.14.19, running with linear solver MUMPS 5.8.2.

Number of nonzeros in equality constraint Jacobian...:      271
Number of nonzeros in inequality constraint Jacobian.:      180
Number of nonzeros in Lagrangian Hessian.............:        0

Total number of variables............................:       63
                     variables with only lower bounds:        1
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:       60
Total number of inequality constraints...............:       61
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:       61

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  3.2401000e+05 0.00e+00 1.00e+00   0.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  3.2403228e+05 3.69e-14 1.41e-02  -2.0 9.94e-03    -  9.96e-01 1.00e+00h  1
   2  3.2055122e+05 3.77e-06 1.36e-04  -5.3 5.28e-02    -  9.90e-01 1.00e+00f  1
   3  1.2932991e+05 2.49e+00 4.12e-02  -5.1 6.13e+00    -  9.89e-01 5.94e-01f  1
   4  1.4870286e+05 1.45e+00 1.23e+00  -4.9 1.93e+00    -  1.00e+00 2.29e-01f  1
   5  1.1307417e+05 1.28e+00 2.83e-01  -4.8 1.87e+00    -  1.00e+00 6.82e-01h  1
   6  2.1771590e+06 5.46e+00 3.32e+01  -2.9 7.85e+01    -  9.67e-01 1.32e-01f  1
   7  1.9320195e+06 6.39e+00 1.96e+02  -2.6 7.36e+00    -  1.18e-02 5.79e-01h  1
   8  1.9324280e+06 6.42e+00 9.16e+02  -2.6 5.58e+00    -  1.00e+00 5.48e-03h  1
   9  2.0054702e+06 6.31e+00 1.22e+03  -2.6 6.39e+00    -  5.13e-02 4.58e-02h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  2.0056961e+06 6.31e+00 3.95e+03  -2.6 5.78e+00    -  1.62e-03 1.66e-04h  1
  11  2.3155204e+06 5.84e+00 2.94e+03  -2.6 9.30e+00    -  9.22e-04 9.04e-02f  1
  12  2.5187679e+06 5.70e+00 1.92e+03  -2.6 8.02e+00    -  1.95e-01 5.16e-02h  1
  13  2.5349819e+06 5.69e+00 3.02e+03  -2.6 1.21e+01    -  1.19e-02 2.35e-03h  1
  14  2.8620146e+06 5.40e+00 9.88e+03  -2.6 1.09e+01    -  1.20e-01 4.97e-02f  1
  15  8.2033055e+06 2.88e+00 3.36e+04  -2.6 1.04e+01    -  5.42e-02 4.53e-01h  1
  16  1.7043861e+07 1.41e-01 1.48e+03  -2.6 4.80e+00    -  9.69e-01 9.02e-01h  1
  17  1.6890133e+07 1.13e-01 3.63e+04  -2.6 4.71e-01    -  8.99e-01 2.00e-01h  1
  18  1.6336180e+07 9.55e-02 1.20e+04  -2.6 4.77e-01    -  3.81e-01 6.31e-01f  1
  19  1.7189242e+07 4.06e-03 4.47e+04  -2.6 3.54e-01    -  6.19e-02 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  20  1.6972350e+07 7.39e-05 2.62e-03  -2.6 8.66e-02    -  9.94e-01 1.00e+00f  1
  21  1.6665026e+07 3.63e-03 4.91e+01  -3.9 3.51e-01    -  7.66e-01 4.49e-01f  1
  22  1.6653241e+07 7.44e-03 2.90e-02  -3.9 2.30e-01    -  1.00e+00 1.00e+00f  1
  23  1.6437398e+07 4.24e-02 2.06e+00  -3.9 5.56e-01    -  8.92e-01 1.00e+00f  1
  24  1.6255387e+07 8.97e-05 2.37e-02  -3.9 7.54e-02    -  3.40e-01 1.00e+00h  1
  25  1.6224119e+07 9.48e-05 1.29e-02  -3.9 3.15e+00    -  6.82e-01 4.03e-03f  2
  26  1.5845220e+07 1.26e-02 5.60e+01  -3.9 1.29e+00    -  2.73e-01 5.07e-01f  1
  27  1.4374217e+07 1.83e-01 9.21e+01  -3.9 1.13e+01    -  1.00e+00 3.53e-01f  1
  28  1.3948387e+07 1.71e-01 2.13e+02  -3.9 2.89e+00    -  1.00e+00 6.37e-02f  1
  29  1.2520204e+07 2.41e-03 4.76e+03  -3.9 6.61e-01    -  2.46e-02 1.00e+00f  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  30  1.2501433e+07 2.71e-07 8.91e-03  -3.9 8.92e-03    -  1.00e+00 1.00e+00h  1
  31  1.2463733e+07 1.39e-05 2.43e-04  -3.9 1.52e-01    -  1.00e+00 1.94e-01f  2
  32  1.2406349e+07 1.85e-05 7.59e-05  -5.8 2.93e-02    -  1.00e+00 9.67e-01f  1
  33  1.2404926e+07 2.71e-08 2.81e-06  -5.8 1.16e-03    -  1.00e+00 1.00e+00h  1
  34  1.2404496e+07 2.24e-09 2.15e-04  -8.7 2.15e-04    -  1.00e+00 9.81e-01h  1
  35  1.2404470e+07 2.19e-10 2.41e-05  -8.7 2.41e-05    -  1.00e+00 9.38e-01h  1
  36  1.2404471e+07 8.88e-15 2.59e-07  -8.7 2.58e-07    -  1.00e+00 1.00e+00f  1
  37  1.2404470e+07 3.55e-15 2.88e-07 -12.3 2.88e-07    -  1.00e+00 1.00e+00f  1
  38  1.2404470e+07 1.78e-15 8.97e-11 -12.3 8.95e-11    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 38

                                   (scaled)                 (unscaled)
Objective...............:   1.2404469932044904e-01    1.2404469932044903e+07
Dual infeasibility......:   8.9661412978295787e-11    8.9661412978295791e-03
Constraint violation....:   9.1623033856588404e-20    1.7763568394002505e-15
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   5.0101162578586281e-13    5.0101162578586282e-05
Overall NLP error.......:   6.4974345416931383e-11    8.9661412978295791e-03


Number of objective function evaluations             = 44
Number of objective gradient evaluations             = 39
Number of equality constraint evaluations            = 44
Number of inequality constraint evaluations          = 44
Number of equality constraint Jacobian evaluations   = 39
Number of inequality constraint Jacobian evaluations = 39
Number of Lagrangian Hessian evaluations             = 0
Total seconds in IPOPT                               = 28.387

EXIT: Optimal Solution Found.
1-element Vector{Float64}:
 -1.5000000149650201

The results on main is way better:


This is Ipopt version 3.14.19, running with linear solver MUMPS 5.8.2.

Number of nonzeros in equality constraint Jacobian...:      271
Number of nonzeros in inequality constraint Jacobian.:      181
Number of nonzeros in Lagrangian Hessian.............:        0

Total number of variables............................:       63
                     variables with only lower bounds:        0
                variables with lower and upper bounds:        0
                     variables with only upper bounds:        0
Total number of equality constraints.................:       60
Total number of inequality constraints...............:       62
        inequality constraints with only lower bounds:        0
   inequality constraints with lower and upper bounds:        0
        inequality constraints with only upper bounds:       62

iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
   0  3.2400000e+05 0.00e+00 2.20e-03   0.0 0.00e+00    -  0.00e+00 0.00e+00   0
   1  3.2399304e+05 3.58e-14 2.13e-03  -8.0 1.00e-02    -  1.00e+00 9.90e-01h  1
   2  3.2525985e+05 8.45e-06 1.09e-04  -9.5 2.39e-01    -  1.00e+00 1.00e+00h  1
   3  3.1650137e+05 3.15e-05 3.85e-03  -6.3 1.21e-01    -  9.90e-01 1.00e+00h  1
   4  2.9849888e+05 1.14e-03 2.22e-01  -7.4 5.31e-01    -  1.00e+00 4.85e-01h  1
   5  2.8580059e+05 2.49e-03 8.67e+00  -7.6 2.35e+00    -  1.00e+00 8.57e-02h  1
   6  1.3045575e+05 2.43e+00 8.87e-01  -7.5 1.04e+01    -  9.85e-01 2.95e-01h  1
   7  1.2954931e+05 1.95e+00 1.96e+00  -5.6 7.44e+00    -  1.00e+00 1.38e-01h  1
   8  1.0191055e+05 2.06e+00 1.05e+00  -5.5 2.58e+00    -  1.00e+00 3.28e-01h  1
   9  1.0072735e+05 2.05e+00 1.41e+00  -5.8 2.41e+00    -  2.21e-01 1.67e-02h  1
iter    objective    inf_pr   inf_du lg(mu)  ||d||  lg(rg) alpha_du alpha_pr  ls
  10  9.5195578e+04 1.96e+00 1.96e+00  -5.2 2.39e+00    -  1.00e+00 1.04e-01h  1
  11  1.4464578e+05 8.68e-01 3.08e-04  -4.7 1.23e+00    -  1.00e+00 1.00e+00h  1
  12  1.3198381e+05 2.80e-01 1.82e-01  -5.8 7.12e-01    -  1.00e+00 8.09e-01h  1
  13  1.2831229e+05 2.20e-02 7.10e-05  -6.5 4.13e-01    -  1.00e+00 1.00e+00h  1
  14  1.2812679e+05 7.51e-04 1.68e-06  -7.5 3.91e-02    -  1.00e+00 1.00e+00h  1
  15  1.2810475e+05 2.47e-05 2.53e-08  -9.6 1.56e-03    -  1.00e+00 9.69e-01h  1
  16  1.2810408e+05 3.11e-09 4.20e-09 -12.3 5.89e-05    -  1.00e+00 1.00e+00h  1

Number of Iterations....: 16

                                   (scaled)                 (unscaled)
Objective...............:   1.2810408484187311e-03    1.2810408484187310e+05
Dual infeasibility......:   4.1966114646936961e-09    4.1966114646936958e-01
Constraint violation....:   1.6049625022104373e-13    3.1116478005355219e-09
Variable bound violation:   0.0000000000000000e+00    0.0000000000000000e+00
Complementarity.........:   5.0384975200402182e-13    5.0384975200402179e-05
Overall NLP error.......:   4.1966114646936961e-09    4.1966114646936958e-01


Number of objective function evaluations             = 17
Number of objective gradient evaluations             = 17
Number of equality constraint evaluations            = 17
Number of inequality constraint evaluations          = 17
Number of equality constraint Jacobian evaluations   = 17
Number of inequality constraint Jacobian evaluations = 17
Number of Lagrangian Hessian evaluations             = 0
Total seconds in IPOPT                               = 23.984

EXIT: Optimal Solution Found.
1-element Vector{Float64}:
 1.2717046667926974

I'm not sure what's happening. I will continue my investigations. Any clue @cvanaret on why the iterations could suddenly increase like this ?

edit : There is only one box constraint here, the slack $\epsilon \ge 0$, for constraint softening. This decision variable tends to take very small values since there is a $(10^5) \epsilon^2$ term in the objective function.

edit 2: It converges to the good solution if I set hessian=true in the NonLinMPC constructor, that is, provide an exact Hessian instead of the builtin LBFGS solver of Ipopt. Maybe it's not a bug on my side. Maybe the builtin LBFGS has difficulties when it's a bound constraint instead of an inequality constraint because it no longer appears in the Jacobian and Hessian? I will try Uno to see what's happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants